/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.friend;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import net.sf.json.JSONObject;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.util.Iterator;

/**
 *
 * @author Austin
 */
public class test {

    private static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            //递归删除目录中的子目录下
            for (int i = 0; i < children.length; i++) {
//                boolean success = deleteDir(new File(dir, children[i]));
                boolean success = new File(dir, children[i]).delete();
                if (!success) {
                    return false;
                }
            }
        }
        // 目录此时为空，可以删除
        return dir.delete();
    }

    public static void main(String[] args) throws DocumentException, ParserConfigurationException {
        try {
            // read file content from file
            StringBuffer sb = new StringBuffer("");

            FileReader reader = new FileReader("C:\\Users\\Austin\\Desktop\\biz_pa_reads_20170909_23.txt");
            BufferedReader br = new BufferedReader(reader);
            String str = null;

            while ((str = br.readLine()) != null) {
                if (str != null && !str.isEmpty()) {
                    JSONObject object;
                    try {
                        object = JSONObject.fromObject(str);
                    } catch (Exception e) {
                        System.out.println(e);
                        continue;
                    }
//                    System.out.println(object.get("num"));
                    if(object.getLong("num")>1000){
                        sb.append(object.get("num")+"\n");
                    }
                    
                }
            }

            br.close();
            reader.close();
            
            FileWriter writer = new FileWriter("C:\\Users\\Austin\\Desktop\\aaa.csv");
            BufferedWriter bw = new BufferedWriter(writer);
            bw.write(sb.toString());

            bw.close();
            writer.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        

    }
}
